<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="com.ionglobal.db.*" %>
<%@ page import="com.ionglobal.lib.*" %>
<%@ page import="com.ionglobal.misc.*" %>

<%@ include file="../init_include.jsp" %>
<%@ include file="../init_free.jsp" %>

<%
try
{
	Sysop sysop=(Sysop)session.getAttribute("sysop");
	if ( sysop==null)
	{
		response.sendRedirect("../index.jsp");
		return;
	}	
			
	String relativePath=request.getParameter("path");
	String module=request.getParameter("module");
	String rstUrl=request.getParameter("rstUrl");
	if(rstUrl==null)
		rstUrl="fmsSelectFile.jsp";
	
	if ( (module==null)||(module.length()<1)) module="fms";

	String fileRoot=SysEnv.get("web.fileRoot");
	String filetail=SysEnv.get(""+module+".fileRoot");

	while (fileRoot.endsWith("\\")||fileRoot.endsWith("/"))
		fileRoot=fileRoot.substring(0,fileRoot.length()-1);
	if (fileRoot.length()<1) fileRoot="/";
	filetail=Utilities.chargePathSeparator(filetail);
	if(filetail!=null && filetail.length()>0)
		fileRoot=fileRoot+File.separator+filetail;
	
	String rootUrl=SysEnv.get("web.fileUrl");
	String webtail=SysEnv.get(""+module+".fileUrl");
	while (rootUrl.endsWith("\\")||rootUrl.endsWith("/"))
		rootUrl=rootUrl.substring(0,rootUrl.length()-1);
	if (rootUrl.length()<1) 
		rootUrl="";
	else
		rootUrl="/"+rootUrl+"/";
	webtail=Utilities.chargePathSeparator(webtail);
	if(webtail!=null && webtail.length()>0)
		rootUrl=rootUrl+filetail+"/";
	
	String completePath;
	String smodule = (String)session.getAttribute("FMS_MODULE");	
	if( module == null || module.trim().length() == 0 ){
		module = "fms";
	}
	session.setAttribute("FMS_MODULE",module);

	if ( relativePath==null)
	{
		if( session.getAttribute("FMS_RELATIVEPATH") != null && smodule!= null && module.equals(smodule))
			relativePath = (String)session.getAttribute("FMS_RELATIVEPATH");
		else 
			relativePath="";
	}
	else{
		while (relativePath.indexOf("../")!=-1)
			relativePath=Utilities.strReplace(relativePath,"../","");
		session.setAttribute("FMS_RELATIVEPATH", relativePath );
	}	
	
	relativePath=Utilities.chargePathSeparator(relativePath);
	completePath=fileRoot+File.separator+relativePath;
	String filename=request.getParameter("file");
	if(filename!=null && filename.length()>0)
	{
		zip zip=new zip();
		zip.extractZip(completePath,completePath+File.separator+filename);
	}			
	String desturl="fileManage.jsp?path="+relativePath;
	if(request.getParameter("rstUrl")!=null)
		desturl=request.getParameter("rstUrl")+"?path="+relativePath+"&oldPath="+request.getParameter("oldPath")+"&module="+request.getParameter("module");	
} catch(Exception error)
{
	out.print(error);
}%>
	

